#include <iostream>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <string>
#include <algorithm>
using namespace std;

unordered_set<string> ans;
string aa;
void dfs(int x, vector<int>& nums){
    if(x == nums.size()){
        ans.insert(aa);
        return;
    }
    aa += "#";
    aa += to_string(nums[x]);
    dfs(x+1, nums);
    aa.erase(aa.rfind('#'));
    dfs(x+1, nums);
    return;
}
vector<vector<int>> subsetsWithDup(vector<int>& nums) {
    sort(nums.begin(), nums.end());
    dfs(0, nums);
    vector<vector<int>> ret;
    for(auto it : ans){
        vector<int> tmp;
        char *p = (char *)it.c_str();
        char *token = strtok(p, "#");
        while(token != nullptr){
            tmp.push_back(stoi(token));
            token = strtok(nullptr, "#");
        }
        ret.push_back(tmp);
    }
    return ret;
}

int main(){
    vector<int> nums = {1,2,2};
    vector<vector<int>> ans = subsetsWithDup(nums);
   
    for(int i=0;i<ans.size();i++){
        for(int j=0;j<ans[i].size();j++){
            cout << ans[i][j] << ", ";
        }
        cout << endl;
    }
}